package com.doit.hbase.client2;

import com.doit.hbase.utils.HbaseUtils;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.*;

import java.util.Iterator;

/**
 * @DATE 2021/12/16/14:32
 * @Author MDK
 * @Version 2021.2.2
 **/
public class C02_Filter03 {
    public static void main(String[] args) throws Exception {
        Connection connection = HbaseUtils.getConnection();
        Table table = HbaseUtils.getTable("tb_teacher",connection);
        Scan scan = new Scan();
        //设置过滤器  过滤数据
        //参数一  与二进制值的运算关系表示符号
        //参数二  二进制的值
        ValueFilter valueFilter = new ValueFilter(CompareOperator.EQUAL, new BinaryComparator("zss".getBytes()));
        //属性过滤器  设置属性,选出显示name属性的过滤器  不能重复设置属性,多次set
        QualifierFilter qualifierFilter = new QualifierFilter(CompareOperator.EQUAL, new SubstringComparator("name"));

        //多次筛选 fileterlist
        FilterList filterList = new FilterList();
        filterList.addFilter(qualifierFilter);
        filterList.addFilter(valueFilter);
        scan.setFilter(filterList);

        //扫描数据
        ResultScanner results = table.getScanner(scan);
        Iterator<Result> iterator = results.iterator();
        while (iterator.hasNext()){
            Result result = iterator.next();
            HbaseUtils.show(result);
        }
        table.close();
        connection.close();
    }
}
